package com.cgb2110.serve.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cgb2110.serve.mapper.MenuRoleMapper;
import com.cgb2110.serve.pojo.MenuRole;
import com.cgb2110.serve.pojo.RespBean;
import com.cgb2110.serve.service.IMenuRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Larry
 * @since 2021-12-20
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements IMenuRoleService {
    @Autowired
    private MenuRoleMapper menuRoleMapper;

    @Override
    @Transactional
    public RespBean updateMenuRole(Integer rid, Integer[] mids) {
        if (mids.length>0&&mids!=null){
            menuRoleMapper.delete(new QueryWrapper<MenuRole>().eq("rid", rid));
        }
       Integer i = menuRoleMapper.insertRecord(rid,mids);
        if (i>0){
            return RespBean.success("更新成功");

        }
        return RespBean.error("更新失败");
    }
}
